/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//<editor-fold defaultstate="collapsed" desc=" IVAN DUQUE ">


package GUI;
import Controllers.PersonJpaController;
import Entities.Person;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;


public class Login {

    private String name;
    private String lastName;
    private String enteredPassword;
    private String password = "JPA_PRACTICE";
    
    public Login(String name, String lastName, String password) {
        this.name=name;
        this.lastName=lastName;
        this.enteredPassword = password;
        
    }
    
    public boolean verifyLoginData(){
        boolean succesfull=false;
        
        List<Person> listPersons;
        
        
        EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("HPVAS_HPU");
        EntityManager em = emFactory.createEntityManager();
        PersonJpaController perCtrl = new PersonJpaController(emFactory);
        listPersons = em.createNamedQuery("Person.findByPerType")
                .setParameter("perType", "employee")
                .getResultList();
        
        
        for(Person per : listPersons){
            if(per.getPerName().equals(name) && per.getPerLastName().equals(lastName) && enteredPassword.equals(password)){
            
                succesfull = true;
                break;
            }
        
        }
        
        
        return succesfull;
    
    }
}
//</editor-fold>